<?php
	
	include '../common.php';
	$a = $_GET['a'];
	$id = $_GET['id'];
	
	switch($a){
		case 'sent':
			$sql = "update ".PRE."order set status='1' where id='{$id}'";
			mysql_query($sql);
			header('location:'.$_SERVER['HTTP_REFERER']);
			break;

		case 'del':
			$status = $_GET['sta'];
			//若订单未完成，删除订单则恢复库存
			if($status < 2){
				//恢复库存量
				$sql = "select goods_id,num from ".PRE."order_goods where order_id='{$id}'";
				$result = mysql_query($sql);
				while($row = mysql_fetch_assoc($result)){
					$goodslist[] = $row;
				}
				foreach($goodslist as $val){
					$sql = "update ".PRE."goods set store = store+'{$val['num']}' where id='{$val['goods_id']}'";
					mysql_query($sql);
				}
			}
			
			//删除mbs_order_goods表中的商品
			$sql = "delete from ".PRE."order_goods where order_id='{$id}'";
			mysql_query($sql);
			//删除order表
			$sql = "delete from ".PRE."order where id='{$id}'";
			mysql_query($sql);
			header('location:'.$_SERVER['HTTP_REFERER']);
			break;
	
	}
?>
